home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / bbs / low_1123.zip / LOG170.ZIP / LOG.CMD < prev   
OS/2 REXX Batch file  |  1996-10-25  |  20KB  |  607 lines

  1. /* LOG.CMD - REXX program to manage Lora's logfile, ver. 1.70
  2.   - 25 October, 1996 by Elliott Goodman, 1:2004/102 -
  3. */
  4.  
  5. /* check whether RxFuncs are loaded. If not, load them. */       
  6.                                                                  
  7. if RxFuncQuery('SysLoadFuncs') then                              
  8. do                                                               
  9.         call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  10.         call SysLoadFuncs                                        
  11. end                                                              
  12.  
  13. path.1 = 'd:\lora'        /* set up directories */
  14. path.2 = 'd:\lora\lang'
  15.  
  16. /* call the date function and get a unique number based on it */
  17. day_index = SPECIFIED_DATE_IN_DAYS( DATE('U') )
  18. day_index = day_index - 1    /* if it's after midnight, when we are
  19.                 going to do our stuff, we want
  20.                 yesterday's date */
  21.  
  22. init_file = 'd:\lora\lang\init.log' /* file to initialize lora.zip */
  23. call SysFileDelete(init_file)            /* kill old file, if present */ 
  24. door_file = 'd:\lora\lang\doors.txt'
  25.  
  26. m_txt = 'This is Lora.Zip'
  27. call lineout init_file, m_txt
  28.  
  29. call directory path.2        /* move to proper dir */
  30. old = 0                /* flag to indicate oldlora.zip exists */
  31.  
  32. call SysFileTree path.2||'\oldlora.zip', files, 'F'
  33. if files.0 \= 0 then
  34.   do
  35.     old = 1            /* if it exists, set flag */
  36.   end
  37.  
  38. /* all this is to get a month index for the current lora.zip file */
  39. call SysFileTree path.2||'\lora.zip', files, 'F'
  40. if files.0 = 0 then
  41.   do
  42.     'zip lora.zip init.log'
  43.   end
  44.   else
  45.   do
  46.       parse var files.1,
  47.          file_date,                  
  48.          file_time,                  
  49.          file_size,                  
  50.          file_attr,                  
  51.          file_name                   
  52.  
  53.     parse var file_date,
  54.       mm '/',
  55.       dd '/',
  56.       yy
  57.  
  58.     lora_zip_month = mm
  59.   end
  60.  
  61. /* set initial conditions: make sure a lora.log exists in the \lang subdir */
  62. call SysFileTree path.2||'\lora.log', files, 'F'
  63. if files.0 = 0 then 
  64.   do
  65.     'copy d:\lora\lora.log d:\lora\lang'
  66.     'del d:\lora\lora.log'
  67.     'exit'
  68.   end
  69.  
  70. /* this is an error condition that should never happen */
  71. if files.0 > 1 then
  72.   do
  73.     say 'More than one log file in d:\lora\lang'
  74.     'exit'
  75.   end
  76.  
  77. /* okay, files.0 = 1 (one lora.log file in \lora\lang exists)
  78. this is all to get the date of the file */
  79. do
  80.       parse var files.1,         /* log file in d:\lora\lang */
  81.          file_date,                  
  82.          file_time,                  
  83.          file_size,                  
  84.          file_attr,                  
  85.          file_name                   
  86.       file_name = STRIP( file_name ) 
  87.     lang_log = file_name
  88.     lang_date = file_date
  89.  
  90. /* now get the date of the current lora.log file in lora's subdir */
  91.     call SysFileTree path.1||'\lora.log', files, 'F'
  92.       parse var files.1,         /* log file in d:\lora */
  93.          file_date,                  
  94.          file_time,                  
  95.          file_size,                  
  96.          file_attr,                  
  97.          file_name                   
  98.       file_name = STRIP( file_name ) 
  99.     lora_log = file_name
  100.     lora_date = file_date
  101.  
  102. /* set a month index for the logfile for comparison with lora.zip */
  103.     parse var file_date,
  104.       mm '/',
  105.       dd '/',
  106.       yy
  107.  
  108.     lora_month = mm
  109.  
  110. /* if dates are equal, it's the same day so just append the log to
  111. the save log and erase the current one */
  112.       if lora_date = lang_date then
  113.     do
  114.         'cd \lora\lang'
  115.         'copy lora.log+d:\lora\lora.log lora.log'
  116.         'del d:\lora\lora.log'
  117.         'exit'
  118.     end
  119.  
  120. /* okay, dates are NOT equal. That means a new day has rolled by.
  121. First, now test if a new month has also passed. If so.... */
  122. if lora_month \= lora_zip_month then
  123.   do
  124. /* ...and we have an oldlora.zip file (a month's worth of logs)
  125. delete it and rename the current month's lora.zip to oldlora.zip */
  126.     if old = 1 then
  127.       do
  128.         'del d:\lora\lang\oldlora.zip'
  129.       end
  130.     'ren d:\lora\lang\lora.zip oldlora.zip'
  131.  
  132. /* attempt to run in background.... */
  133.         'detach d:\lora\lang\eom.cmd > d:\lora\lang\eom.rpt'
  134. /*        call "d:\lora\lang\eom.cmd" */
  135.  
  136. /* create a new lora.zip with a 20 byte nul file so we can
  137. move lora.logs into it without error */
  138.     'zip lora.zip init.log'
  139.   end
  140.  
  141. /* delete yesterday's door tracking file */
  142.   call SysFileDelete(door_file)
  143.   call SysSleep 1
  144.  
  145. /* now, finally, create a unique name for yesterday's logfile and
  146. move it into our zip file. */    
  147.       'cd \lora\lang'
  148.  
  149.         say 'Door Tracker....'
  150.         call Door_tracker
  151.         call SysSleep 1
  152. /* might need to change for YOUR system */
  153.         'copy d:\lora\lang\doors.txt d:\lora\misc\bullet10.bbs'
  154.  
  155.         say "Running MSGCNT.CMD. Please wait...." 
  156.         call "d:\lora\lang\msgcnt.cmd"            
  157.  
  158.         say "Running CALLERS.CMD...."  
  159.         call "d:\lora\lang\callers.cmd"
  160.  
  161.         say 'Remove routine....'
  162.     call remove_stuff
  163.  
  164.         say 'Zipping....'
  165.       temp_name = day_index||'.log'
  166.       'ren d:\lora\lang\lora.log '||temp_name
  167.       'zip -m lora.zip '||temp_name
  168.  
  169. /* copy today's logfile into our storage area and delete the 
  170. current one */
  171.       'copy d:\lora\lora.log d:\lora\lang'
  172.       'del d:\lora\lora.log'
  173.       'exit'
  174. end
  175.  
  176. 'exit'
  177.  
  178. /* end of LOG.CMD */
  179.  
  180. /*------------------------------------------------*/  
  181. /* Convert calendar date to consistent date index            */  
  182. /*------------------------------------------------*/  
  183. SPECIFIED_DATE_IN_DAYS:                               
  184.    Procedure                                          
  185.                                                       
  186. parse arg,                                            
  187.    mm '/',                                            
  188.    dd '/',                                            
  189.    yy                                                 
  190.                                                       
  191. days_by_month = '31 28 31 30 31 30 31 31 30 31 30 31' 
  192. current_number_of_days = (yy * 365) + dd              
  193. do m = 1 while m < mm                                 
  194.    current_number_of_days = current_number_of_days +, 
  195.       WORD( days_by_month, m )                        
  196. end                                                   
  197. return current_number_of_days                         
  198. /* the above procedure was written by Dick Goran. I could come up
  199. with something that does the same thing but I like the way he does
  200. it so copied it. Doubt he'd mind since he posted it in a public echo! */
  201.  
  202. /*------------------------------------------------*/  
  203. /* removes lines from the log with certain key words         */
  204. /*------------------------------------------------*/  
  205. Remove_stuff:
  206.  
  207. /* we're in \lora\lang and we have one lora.log file there.
  208. we're going to move the file into the zip archive so this
  209. is only done once a day, just before the previous day's logfile
  210. is zipped. */
  211.  
  212. /* time process */
  213. call time('R')
  214.  
  215. /* first, set up the phrases we DON'T want */
  216.  
  217. phrase. = ''
  218. phrase.1 = 'UL-Z/32'
  219. phrase.2 = 'Nothing to send'
  220. phrase.3 = 'sharing enabled'
  221. phrase.4 = 'STATS:'
  222. phrase.5 = 'Ring'
  223. phrase.6 = 'Deleted DIR Xflag'
  224. phrase.7 = 'ALLFIX+'
  225. phrase.8 = 'EMSI'
  226. phrase.9 = 'Type=2+'
  227. phrase.10 = 'Return code'
  228. phrase.11 = 'Remote Uses'
  229. phrase.12 = 'Offer:'
  230. phrase.13 = 'Aka:'
  231. phrase.14 = 'D:\LORA\INET.CMD'
  232. phrase.15 = 'Flags:'
  233. phrase.16 = 'DL-Z/32'
  234.  
  235. /* Total number of phrases */
  236. R_S_Items = 16
  237.  
  238. /* create file to store phrase frequencies */
  239. remove_file = 'D:\LORA\LANG\1REMOVE.TXT'
  240. /* remove previous Output file, if present */  
  241. /* call SysFileDelete(remove_file) */
  242.  
  243. talley. = ''
  244.  
  245. /* zero talley scores */
  246. do talley_count = 1 to R_S_Items
  247.     talley.talley_count = 0
  248.     end
  249.  
  250. /* track # of successful finds */
  251. skip_line = 0
  252.  
  253. 'ren lora.log lora.bak'        /* save it, just in case */
  254. in_name = 'lora.bak'        /* set up work names */
  255. out_name = 'lora.log'
  256. do until lines(in_name) = 0        /* read in each line */
  257.   work_line = linein(in_name)        /* current line to examine */
  258.   found_phrase = 0            /* zero flag */
  259.   do i = 1 to R_S_Items        /* cycle thru phrases */
  260.   j = wordpos(phrase.i, work_line)    /* look for the phrase */
  261.   if j \= 0 then do            /* phrase found */
  262.       found_phrase = 1        /* set flag */
  263.       talley.i = talley.i + 1
  264.       leave i                /* stop looking in this line */
  265.       end    /* end if j \= */
  266.   end        /* end do i */
  267.   if found_phrase = 1 then do        /* if found, don't write line */
  268.       skip_line = skip_line + 1
  269.       iterate                /* skip to next line */
  270.       end    /* end if found */
  271.   else do                /* phrase not found */
  272.       call lineout out_name, work_line    /* write line */
  273.       end    /* end else do */
  274. end        /* end do until */
  275. call lineout in_name            /* close files */
  276. call lineout out_name
  277. 'del lora.bak'            /* done with backup file */
  278.  
  279. /* talley & # of lines not written */
  280. m_txt = 'Phrase Frequencies'
  281. call lineout remove_file, m_txt
  282. m_txt = date('U') 
  283. m_txt = 'Date:' m_txt
  284. call lineout remove_file, m_txt
  285. m_txt = ''
  286. call lineout remove_file, m_txt
  287. m_txt = 'Use to tune this module; put most frequent phrases first'
  288. call lineout remove_file, m_txt
  289. m_txt = ''
  290. call lineout remove_file, m_txt
  291.  
  292.  
  293. do talley_count = 1 to R_S_Items
  294.     m_txt = 'Phrase' || talley_count '=' talley.talley_count 
  295.     call lineout remove_file, m_txt
  296.     end
  297.  
  298. m_txt = "Lines skipped:" skip_line
  299. call lineout remove_file, m_txt
  300.  
  301. /* Determine time elapsed */                                        
  302. time_spent = trunc( time('E'))
  303.  
  304. /* calculate a "kill rate" to monitor tuning progress */
  305. kill_rate = skip_line / time_spent
  306. kill_rate = trunc(kill_rate, 2)
  307. m_txt = 'Lines skipped per second:' kill_rate
  308. call lineout remove_file, m_txt
  309.  
  310. m_txt = 'Time:'
  311. if time_spent > 3599 then do
  312.   hours = time_spent % 3600
  313.   time_spent = time_spent - (3600 * hours)
  314.   if hours > 1 then
  315.     m_txt = m_txt hours 'hours'
  316.   else
  317.     m_txt = m_txt hours 'hour'
  318.   end
  319.  
  320. if time_spent > 59 then do
  321.   minutes = time_spent % 60
  322.   time_spent = time_spent - (60 * minutes)
  323.   if minutes > 1 then
  324.     m_txt = m_txt minutes 'minutes'
  325.   else
  326.     m_txt = m_txt minutes 'minute'
  327.   end
  328.  
  329. if time_spent > 1 then
  330.   m_txt = m_txt time_spent 'seconds.'
  331. else
  332.   m_txt = m_txt time_spent 'second.'
  333.  
  334. call lineout remove_file, m_txt
  335.  
  336. Call SysSleep 2
  337. Call lineout remove_file
  338. return                /* continue processing lora.log */
  339.  
  340. /*------------------------------------------------*/  
  341. /* Door tracker - Tracks door usage                            */
  342. /*------------------------------------------------*/  
  343.  
  344. Door_tracker:  Procedure
  345.  
  346. phrase = 'External'                                                   
  347. phrase2 = 'Returned'
  348. phrase3 ='D:\LORA\LORD1.BAT'
  349. phrase4 = 'D:\LORA\DOORS\EZELS.BAT'
  350. phrase5 ='D:\LORA\PLANET1.BAT'
  351. phrase6 = 'Write'
  352. phrase7 = 'Connect FAX'
  353. phrase8 = 'Calls=1,'
  354. phrase9 = 'System call'
  355. phrase10 = 'Receiving' 
  356. phrase12 = 'D:\LORA\DOORS\EZVOTE\EZVOTE.BAT'
  357. phrase13 = 'D:\LORA\DOORS\SPIKE\SPIKE.BAT'  
  358. phrase14 = 'D:\LORA\ICECHAT.BAT'
  359. phrase15 = 'D:\LORA\DOORS\USURP\USURP.BAT'
  360. phrase16 = 'D:\LORA\DOORS\INET\INET.EXE'
  361. phrase17 = 'D:\LORA\BMAST.BAT'
  362. phrase19 = 'D:\LORA\WOT1.BAT'
  363. phrase20 = 'D:\LORA\SDL.BAT'
  364. phrase21 = 'D:\LORA\TC.BAT'
  365. phrase22 = 'D:\LORA\FILE\TOSS.CMD'
  366.  
  367. color = "C"
  368. count = 0                       /* count of times door is entered */
  369. ice = 0
  370. lord = 0                                                            
  371. planet = 0                                                          
  372. ezrom = 0                                                           
  373. ezvote = 0 
  374. spike = 0  
  375. chat = 0
  376. bota = 0
  377. inet = 0
  378. bmast = 0
  379. wot = 0
  380. sdl = 0
  381. top = 0
  382. olr = 0
  383. fax_count = 0
  384. Sys_Txt = 'No System Calls??'
  385. BBS_calls = 0
  386. max_time = (24 * 3600)                                                
  387. total_time = 0                                                        
  388. save_file = 'd:\lora\lang\doors.txt'                                  
  389. total_hours = 0                                                       
  390. total_minutes = 0                                                     
  391. total_seconds = 0                                                     
  392.  
  393. m_txt = color                                                                      
  394. call lineout save_file, m_txt                                         
  395. m_txt = date('U')                                                     
  396. call lineout save_file, m_txt                                         
  397. m_txt = "--------"
  398. call lineout save_file, m_txt
  399.  
  400. in_name = 'lora.log'            /* set up work names */
  401.  
  402. do until lines(in_name) = 0             /* read in each line */
  403.   work_line = linein(in_name)           /* current line to examine */
  404.   j = wordpos(phrase, work_line)      /* look for the phrase */
  405.   if j \= 0 then do                     /* phrase found */
  406.       next_line = linein(in_name)
  407.       k = wordpos(phrase2, next_line)
  408.       if k \= 0 then do
  409. /* Okay, work_line has 'External' in it and next_line has 'Returned' in it.
  410. Therefore, a user has gone to a door and returned. Now, let's parse the lines */
  411.  
  412.         count = count + 1
  413. /* find out which door was run */                             
  414.                                                               
  415.         n = wordpos(phrase3, work_line) /* Test for Legend */ 
  416.           if n \= 0 then
  417.             lord = lord + 1
  418.                                                               
  419.         n = wordpos(phrase4, work_line) /* Test for EZ-Rom */
  420.           if n \= 0 then
  421.             ezrom = ezrom + 1
  422.                                                               
  423.         n = wordpos(phrase5, work_line) /* Test for Planets */
  424.           if n \= 0 then
  425.             planet = planet + 1
  426.  
  427.         n = wordpos(phrase12, work_line)   /* Test for EZ-Vote */ 
  428.           if n \= 0 then
  429.             ezvote = ezvote + 1
  430.                                                                   
  431.         n = wordpos(phrase13, work_line)  /* test for Spiked! */  
  432.           if n \= 0 then
  433.             spike = spike + 1
  434.  
  435.         n = wordpos(phrase14, work_line)  /* test for IceChat */
  436.           if n \= 0 then
  437.             chat = chat + 1
  438.  
  439.         n = wordpos(phrase15, work_line)  /* test for Usurper */
  440.           if n \= 0 then
  441.             bota = bota + 1
  442.  
  443.         n = wordpos(phrase16, work_line)  /* test for Inet */
  444.           if n \= 0 then
  445.             inet = inet + 1
  446.  
  447.         n = wordpos(phrase17, work_line)  /* test for BoardMaster */
  448.           if n \= 0 then
  449.             bmast = bmast + 1
  450.  
  451.         n = wordpos(phrase19, work_line)  /* World of Tears */
  452.           if n \= 0 then
  453.             wot = wot + 1
  454.  
  455.         n = wordpos(phrase20, work_line)  /* Stardock Loco */
  456.           if n \= 0 then
  457.             sdl = sdl + 1
  458.  
  459.         n = wordpos(phrase21, work_line)  /* Top Cop */
  460.           if n \= 0 then
  461.             top = top + 1
  462.  
  463.         n = wordpos(phrase22, work_line)  /* TOSS.CMD */
  464.           if n \= 0 then
  465.             count = count - 1
  466.  
  467.         parse var work_line ':' start_time junk
  468.         parse var next_line ':' end_time junk
  469.         parse var start_time shour ':' smin ':' ssec
  470.         parse var end_time ehour ':' emin ':' esec
  471.         stotal = (3600 * shour) + (60 * smin) + ssec
  472.         etotal = (3600 * ehour) + (60 * emin) + esec
  473.         if stotal > etotal then
  474.           this_time = (max_time - stotal) + etotal
  475.         else
  476.           this_time = etotal - stotal
  477.         total_time = total_time + this_time
  478.  
  479.         end /* k \= */
  480.       k = wordpos(phrase6, next_line)
  481.       if k \= 0 then do
  482.     ice = ice + 1
  483.         count = count + 1
  484.       end /* if k \= 0 */     
  485.  
  486.    end       /* end if j \= */
  487.  
  488. /* check for a few other lines in the log */
  489.     else do                           
  490.  
  491. /* check for offline messages written */
  492.       j = wordpos(phrase6, work_line) 
  493.       if j \= 0 then                  
  494.         olr = olr + 1
  495.  
  496. /* check for fax calls */
  497.       j = wordpos(phrase7, work_line) 
  498.       if j \= 0 then                  
  499.         fax_count = fax_count + 1     
  500.  
  501. /* check for new callers. if found, announce in track file */
  502.       j = wordpos(phrase8, work_line)                              
  503.       if j \= 0 then                                               
  504.          do                                                        
  505.            parse upper var work_line . . first_name last_name 'OFF-LINE.' dummy
  506.            m_txt = "New caller: " first_name last_name
  507.            call lineout save_file, m_txt
  508.            end /* j \= 0 */
  509.  
  510. /* track high system call number */
  511.        j = wordpos(phrase9, work_line)
  512.        if j \= 0 then
  513.        do
  514.            parse var work_line . . Sys_Txt
  515.            BBS_calls = BBS_calls +1
  516.            end
  517.  
  518. /* monitor files received */
  519.         j = wordpos(phrase10, work_line)
  520.         if j \= 0 then
  521.         do
  522.             parse var work_line . . to_where dummy 
  523.             select                                           
  524.                when left(to_where, 13) = 'FILE\UNCHECK\' then do
  525.                   m_txt = 'File Uploaded:' to_where              
  526.                   call lineout save_file, m_txt
  527.                   end
  528.                otherwise                                     
  529.                   iterate                                    
  530.                end                                           
  531.             end
  532.  
  533.       end /* else j */
  534.  
  535. end             /* end do until */
  536. call lineout in_name                    /* close files */
  537.  
  538. /* save high system call number */
  539. m_txt = "BBS Calls:" BBS_calls || ", High" || Sys_Txt
  540. call lineout save_file, m_txt
  541.  
  542. if total_time > 3600 then do
  543.   total_hours = total_time % 3600
  544.   total_time = total_time // 3600
  545.   end
  546.  
  547. if total_time > 60 then do
  548.   total_minutes = total_time % 60
  549.   total_time = total_time // 60
  550.   end
  551.  
  552. total_seconds = total_time
  553.  
  554. /* change total to EXCLUDE Ice Edit */
  555. /* count = count - ice */
  556.  
  557. m_txt = "Total times in doors yesterday =" count
  558. call lineout save_file, m_txt
  559. m_txt = "LORD =" lord "EZ-ELS =" ezrom "EZ-Vote =" ezvote
  560. call lineout save_file, m_txt
  561. m_txt = "Spiked! =" spike "Usurper =" bota "Planets =" planet
  562. call lineout save_file, m_txt
  563. m_txt = "Bmast'r =" bmast  "World of Tears =" wot
  564. call lineout save_file, m_txt
  565. m_txt = "Stardock Loco =" sdl "Top Cop! =" top
  566. call lineout save_file, m_txt
  567. m_txt = " "
  568. call lineout save_file, m_txt
  569.  
  570. m_txt = "Time in doors: Hours:" total_hours||", Minutes:" total_minutes
  571. call lineout save_file, m_txt
  572.  
  573. m_txt = " "
  574. call lineout save_file, m_txt
  575.  
  576. if ice = 1 then                        
  577.    m_txt = "Ice Edit wrote" ice "message." 
  578. else                                   
  579.    m_txt = "Ice Edit wrote" ice "messages."
  580. call lineout save_file, m_txt
  581.  
  582. if olr = 1 then
  583.    m_txt = "One Offline message received."
  584. else
  585.    m_txt = olr "Offline messages received."
  586. call lineout save_file, m_txt
  587.  
  588. if chat = 1 then                      
  589.    m_txt = "Ice Chat called" chat "time." 
  590. else                                  
  591.    m_txt = "Ice Chat called" chat "times."
  592. call lineout save_file, m_txt
  593.  
  594. if inet = 1 then                      
  595.    m_txt = "Inet called" inet "time." 
  596. else                                  
  597.    m_txt = "Inet called" inet "times."
  598. call lineout save_file, m_txt
  599.  
  600. m_txt = "Faxes received:" fax_count
  601. call lineout save_file, m_txt
  602. m_txt = "------------------------------"
  603. call lineout save_file, m_txt
  604. call lineout save_file
  605.  
  606. return
  607.